package com.zhuiYun.project.api.commoditycomment.mapper;
import com.zhuiYun.project.api.commoditycomment.entity.CommodityComment;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName CommodityMapper
 * @Description TODO 商品详情dao层接口
 * @Author 赵笛
 * @Date 2023/4/4 16:02
 **/
@Mapper
public interface CommodityCommentMapper extends BaseMapper<CommodityComment> {

    /**
     * @Author 赵笛
     * @Description TODO getCommentByCommodityId
     * @Date 2023/4/5 12:46
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param commodityId
     */
    @Select("select cc.*,u.nick_name as name,u.avatar_url as url from commodity_comment cc " +
            "left join user u " +
            "on u.id = cc.user_id " +
            "where commodity_id = #{commodityId} limit 2")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "commodityId",column = "commodity_id"),
            @Result(property = "content",column = "content"),
            @Result(property = "pictureGroup",column = "picture_group"),
            @Result(property = "videoGroup",column = "video_group"),
            @Result(property = "productDescriptionRating",column = "product_description_rating"),
            @Result(property = "sellerAttitudeRating",column = "seller_attitude_rating"),
            @Result(property = "shippingSpeedRating",column = "shipping_speed_rating"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "deleteFlag",column = "delete_flag"),
    })
    List<CommodityComment> getCommentByCommodityId(@Param("commodityId") Integer commodityId);
    /**
     * @Author lzk
     * @Description 计算评论总数量
     * @date 2023/4/7 11:21
     * Return com.zhuiYun.project.api.commoditycomment.entity.CommodityComment
     */
    @Select("select count(*) as totalQuantity from commodity_comment where commodity_id = #{cid} ")
    CommodityComment calculateTheTotalNumberOfComments(@Param("cid") Integer cid);
    /**
     *
     * @Author lzk
     * @Description 查询所有评论
     * @date 2023/4/7 11:57
     * Return
     * @param cid
     */
    @Select("SELECT c.*,u.nick_name as name,u.avatar_url as url FROM commodity_comment c left join user u on c.user_id = u.id WHERE commodity_id = #{cid} ")
    List<CommodityComment> queryAllComments(@Param("cid") Integer cid);
}
